﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using UnityEngine.UI;
using Framework.AssetsManager;

public class TipsPanel: MonoBehaviour {

    static TipsPanel _instance;
    public static TipsPanel Instance
    {
        get
        {
            if (_instance == null)
            {
                GameObject panelObj = RM.Instance.GetResource("Prefab/UI/Panel/Tips_Panel-OneBtn") as GameObject;
                panelObj = GameObject.Instantiate(panelObj, GameObject.Find("TipsCanvas").transform);
                _instance = panelObj.GetComponent<TipsPanel>();
            }

            return _instance;
        }
    }


    GameObject btn;
    private Action delegateAction;

    private void Start()
    {
        Button sureBtn = transform.Find("bg/sure").GetComponent<Button>();
        sureBtn.onClick.AddListener(SetSureBtn);
    }

    private void OnEnable()
    {
        transform.SetAsLastSibling();
    }

    public void Init(string content, Action action)
    {
        delegateAction = action;
        gameObject.SetActive(true);
        delegateAction = action;
        gameObject.SetActive(true);
    }

    void SetSureBtn()
    {
        if (delegateAction != null)
            delegateAction();
        gameObject.SetActive(false);
    }

    private void OnDisable()
    {
        delegateAction = null;
    }
}
